{extend name="common/common" /} {block name="style"}
<style type="text/css">
	.container-fluid .btn {
		float: right;
		margin-left: 10px;
	}

	.btn.btn-sm {
		margin: 0;
	}

	.layui-input.layui-unselect {
		width: 182px;
	}
	.layui-input-block{
		margin-left: 80px;
	}
	#cusTable tr{
		cursor: pointer;
	}
</style>
{/block} {block name="content"}
<div class="wrapper wrapper-content animated fadeInRight">
	<div class="ibox float-e-margins">
		<div class="ibox-title">
			<h5>教务老师列表</h5>
		</div>
		<div class="ibox-content">
			<form class="layui-form" action="" id="seaForm">
				<div class="layui-form-item">
					<div class="layui-input-inline" style="width: 200px;">
						<input type="text" name="seaContInfo" id="seaContInfo" placeholder="手机/座机/邮箱" class="layui-input">
					</div>
					<div class="layui-input-inline" style="width: 200px;">
						<input type="text" name="searchText" id="searchText" placeholder="老师名/学校名" class="layui-input">
					</div>

					<div class="layui-inline">
						<button type="button" id="search" class="btn btn-info" style="margin-top: 2px;">查询</button>
					</div>

				</div>
			</form>
			<div class="container-fluid">
				<div class="container-fluid">
					{if authCheck('education/delteacher')}
					<a class="btn btn-danger addproconfig getIDs" href="javascript:delTeacher();" data-param=''>删除老师</a> {/if} {if authCheck('education/addteacher')}
					<a class="btn btn-primary" href="javascript:addTeacher();">添加老师</a> {/if}
				</div>
			</div>
			<table id="cusTable">
				<thead>
					<th>checkbox</th>
					<th class="text-center" data-field="id">ID</th>
					<th class="text-center" data-field="name">老师姓名</th>
					<th class="text-center" data-field="school_name">学校名称</th>
					<th class="text-center" data-field="tel">座机</th>
					<th class="text-center" data-field="phone">手机</th>
					<th class="text-center" data-field="email">邮箱</th>
					<th class="text-center" data-field="status_name">状态</th>
					{if authCheck('user/useradd') || authCheck('education/delteacheruser')}
					<th class="text-center" data-field="user">账号</th>
					{/if}
				</thead>
			</table>
		</div>
	</div>
</div>

<!-- 添加教务老师弹窗 -->
<div id="addTeacherBox" style="display: none;padding: 15px;">
	<form class="layui-form" action="" id="addTeacherForm">
		<div class="layui-form-item">
			<label class="layui-form-label label-required">学校</label>
			<div class="layui-input-block">
				<ul>
					{volist name="$schools" id="v" key="k"}
					<li><input type="checkbox" value="{$v.id}" name="school_id[{$k}]" lay-skin="primary" title="{$v.name}"></li>
					{/volist}
				</ul>
		    </div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label label-required">状态</label>
			<div class="layui-inline">
				<select name="status">
                    <option value="1">在职</option>
                    <option value="2">请假</option>
                    <option value="3">离职交接</option>
                    <option value="1">已离职</option>
                    <option value="2">退休</option>
                    <option value="3">其他</option>
                </select>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label label-required">姓名</label>
			<div class="layui-inline">
				<input type="text" name="name" placeholder="请输入姓名" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label label-required">手机号</label>
			<div class="layui-inline">
				<input type="text" name="phone" placeholder="请输入手机号" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">座机号</label>
			<div class="layui-inline">
				<input type="text" name="tel" placeholder="请输入座机号" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">邮箱</label>
			<div class="layui-inline">
				<input type="text" name="email" placeholder="请输入邮箱" class="layui-input">
			</div>
		</div>
		{if authCheck('education/addteacher')}
		<div class="layui-form-item">
			<label class="layui-form-label"></label>
			<div class="layui-inline">
				<button class="btn btn-primary" type="submit">保存</button>
				<button class="btn btn-danger cancel" type="button">取消</button>
			</div>
		</div>
		{/if}
	</form>
</div>
<!-- 添加教务老师弹窗 -->

<!-- 编辑教务老师弹窗 -->
<div id="editTeacherBox" style="display: none;padding: 15px;">
	<form class="layui-form" action="" id="editTeacherForm">
		<div class="layui-form-item">
			<label class="layui-form-label label-required">学校</label>
			<div class="layui-input-block">
				<ul>
					{volist name="$schools" id="v" key="k"}
					<li><input type="checkbox" class="schools" value="{$v.id}" name="school_id[{$k}]" lay-skin="primary" title="{$v.name}"></li>
					{/volist}
				</ul>
		    </div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label label-required">状态</label>
			<div class="layui-inline">
				<select name="status" id="e_status">
                    <option value="1">在职</option>
                    <option value="2">请假</option>
                    <option value="3">离职交接</option>
                    <option value="4">已离职</option>
                    <option value="5">退休</option>
                    <option value="6">其他</option>
                </select>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label label-required">姓名</label>
			<div class="layui-inline">
				<input type="text" name="name" placeholder="请输入姓名" class="layui-input" id="e_name">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label label-required">手机号</label>
			<div class="layui-inline">
				<input type="text" name="phone" placeholder="请输入手机号" class="layui-input" id="e_phone">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">座机号</label>
			<div class="layui-inline">
				<input type="text" name="tel" placeholder="请输入座机号" class="layui-input" id="e_tel">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">邮箱</label>
			<div class="layui-inline">
				<input type="text" name="email" placeholder="请输入邮箱" class="layui-input" id="e_email">
			</div>
		</div>
		{if authCheck('education/editteacher')}
		<div class="layui-form-item">
			<label class="layui-form-label"></label>
			<div class="layui-inline">
				<input type="hidden" name="id" id="e_id">
				<button class="btn btn-primary" type="submit">保存</button>
				<button class="btn btn-danger cancel" type="button">取消</button>
			</div>
		</div>
		{/if}
	</form>
</div>
<!-- 编辑教务老师弹窗 -->
{/block} {block name="script"}
<script type="text/javascript">
	var IDs = '';

	function initTable() {
		//先销毁表格
		$('#cusTable').bootstrapTable('destroy');
		//初始化表格,动态从服务器加载数据
		$("#cusTable").bootstrapTable({
			method: "get", //使用get请求到服务器获取数据
			url: "./teacher", //获取数据的地址
			striped: true, //表格显示条纹
			pagination: true, //启动分页
			pageSize: 10, //每页显示的记录数
			pageNumber: 1, //当前第几页
			pageList: [5, 10, 15, 20, 25], //记录数可选列表
			sidePagination: "server", //表示服务端请求
			paginationFirstText: "首页",
			paginationPreText: "上一页",
			paginationNextText: "下一页",
			paginationLastText: "尾页",
			queryParamsType: "undefined",
			resizable:true,
			columns: [{
				checkbox: true,
				formatter: function(value, row, index) {
					if (row.state == true) {
						return {
							checked: value, //设置选中
						};
					}
					return value;
				},
			}],
			queryParams: function queryParams(params) { //设置查询参数
				var param = {
					pageNumber: params.pageNumber,
					pageSize: params.pageSize,
					searchText: $("#searchText").val(),
					seaContInfo: $("#seaContInfo").val()
				};
				return param;
			},
			onLoadSuccess: function(res) { //加载成功时执行
				if (111 == res.code) {
					window.location.reload();
				}
				layer.msg("加载成功", {
					time: 1000
				});
			},
			onLoadError: function() { //加载失败时执行
				layer.msg("加载数据失败");
			},
			onDblClickRow: function(row) {
				var school_ids = row.school_id.split(',');
				var aCheckBox = $('.schools');
				for(var i=0;i<school_ids.length;i++){
					for(var j=0;j<aCheckBox.length;j++){
						if(school_ids[i] == aCheckBox[j].value){
							aCheckBox[j].checked = true;
						}
					}
				}
				var aStatus = $('#e_status option');
				for (var i = 0; i < aStatus.length; i++) {
					if (aStatus[i].value == row.status) {
						aStatus[i].selected = true;
					}
				}
				$('#e_id').val(row.id);
				$('#e_name').val(row.name);
				$('#e_tel').val(row.tel);
				$('#e_phone').val(row.phone);
				$('#e_email').val(row.email);
				layui.use(['form'], function() {
					var form = layui.form;
					form.render();
				});
				editbox = layer.open({
					type: 1,
					title: "编辑教务老师信息",
					area: ['350px', '500px'],
					content: $("#editTeacherBox"),
					cancel:resetCheckBox,
				});
			}
		});
	}

	$(function() {
		//调用函数，初始化表格
		initTable();

		layui.use(['form'], function() {
			var form = layui.form;
		});

		//当点击查询按钮的时候执行
		$("#search").bind("click", initTable);

		$('.getIDs').on('click', function() {
			var checkedOn = $('#cusTable').bootstrapTable('getSelections');
			var IDs = '';
			for (var i = 0; i < checkedOn.length; i++) {
				if (i == 0) {
					IDs = checkedOn[0].id;
				} else {
					IDs += ',' + checkedOn[i].id;
				}
			}
			$('.getIDs').attr('data-param', IDs);
		});

		$('.cancel').on('click', function() {
			layer.closeAll();
		});

		$('#addTeacherForm').on('submit', function() {
			var param = $('#addTeacherForm').serialize();
			$.post("./addTeacher", param, function(res) {
				if (res.code == 1) {
					layer.alert(res.msg, {
						title: '友情提示',
						icon: 1,
						closeBtn: 0
					}, function() {
						layer.closeAll();
						resetCheckBox;
						initTable();
					});
				} else {
					layer.msg(res.msg, {
						anim: 6
					});
				}
			});
			return false;
		});

		$('#editTeacherForm').on('submit', function() {
			var param = $('#editTeacherForm').serialize();
			$.post("./editTeacher", param, function(res) {
				if (res.code == 1) {
					layer.alert(res.msg, {
						title: '友情提示',
						icon: 1,
						closeBtn: 0
					}, function() {
						layer.closeAll();
						resetCheckBox;
						initTable();
					});
				} else {
					layer.msg(res.msg, {
						anim: 6
					});
				}
			});
			return false;
		});
	});

	function delTeacher(ids = null) {
		if (ids == null) {
			ids = $('.getIDs').attr('data-param');
		}
		if (ids != '') {
			layer.confirm('确认删除这些数据?', {
				icon: 3,
				title: '提示'
			}, function(index) {
				$.post('./delTeacher', {
					ids: ids
				}, function(res) {
					if (res.code == 1) {
						layer.alert(res.msg, {
							title: '友情提示',
							icon: 1,
							closeBtn: 0
						}, initTable);
					} else {
						layer.msg(res.msg, {
							anim: 6
						});
					}
				});
			});
		} else {
			layer.msg("请选择数据", {
				anim: 6
			});
		}
	}

	function addTeacher() {
		var AddBox = layer.open({
			type: 1,
			title: "添加教务老师",
			area: ['350px', '500px'],
			content: $("#addTeacherBox"),
		})
	}

	function delTeacherUser(id) {
		layer.confirm('确认删除这些数据?', {
			icon: 3,
			title: '提示'
		}, function(index) {
			$.post('./delTeacherUser', {
				id: id
			}, function(res) {
				if (res.code == 1) {
					layer.alert(res.msg, {
						title: '友情提示',
						icon: 1,
						closeBtn: 0
					}, initTable);
				} else {
					layer.msg(res.msg, {
						anim: 6
					});
				}
			});
		});
	}
	function resetCheckBox(){
		var aCheckBox = $('.schools');
		for(var j=0;j<aCheckBox.length;j++){
			aCheckBox[j].checked = false;
		}
		layui.use(['form'], function() {
			var form = layui.form;
			form.render();
		});
	}
</script>
{/block}
